package condition;

import java.awt.Point;
import java.util.ArrayList;
import base.Piece;

public class Rules {
	private boolean supportsMove, supportsDrop, supportsUpgrade, supportsCastle;
	private ArrayList<MoveRule> moveRules;
	private ArrayList<DropRule> dropRules;
	private ArrayList<UpgradeRule> upgradeRules;
	private ArrayList<CastleRule> castleRules;
	
	public Rules(boolean supportsMove, boolean supportsDrop, boolean supportsUpgrade, boolean supportsCastle,
			ArrayList<MoveRule> moveRules, ArrayList<DropRule> dropRules, ArrayList<UpgradeRule> upgradeRules, ArrayList<CastleRule> castleRules) {
		this.supportsMove = supportsMove;
		this.supportsDrop = supportsDrop;
		this.supportsUpgrade = supportsUpgrade;
		this.supportsCastle = supportsCastle;
		
		this.moveRules = moveRules;
		this.dropRules = dropRules;
		this.upgradeRules = upgradeRules;
		this.castleRules = castleRules;
	}
	
	public boolean isValidMove(Piece piece, Point destination) {
		for (MoveRule moveRule : this.moveRules) {
			if (!moveRule.isValidMove(piece, destination)) {
				return false;
			}
		}
		
		return true;
	}
	
	public boolean isValidDrop(Piece piece, Point destination) {
		for (DropRule dropRule : this.dropRules) {
			if (!dropRule.isValidDrop(piece, destination)) {
				return false;
			}
		}
		
		return true;
	}
	
	public boolean isValidUpgrade(Piece piece, String type) {
		for (UpgradeRule upgradeRule : this.upgradeRules) {
			if (!upgradeRule.isValidUpgrade(piece, type)) {
				return false;
			}
		}
		
		return true;
	}
	
	public boolean isValidCastle(Piece piece) {
		for (CastleRule castleRule : this.castleRules) {
			if (!castleRule.isValidCastle(piece)) {
				return false;
			}
		}
		
		return true;
	}
	
	public boolean supportsMove() {
		return this.supportsMove;
	}
	
	public boolean supportsDrop() {
		return this.supportsDrop;
	}
	
	public boolean supportsUpgrade() {
		return this.supportsUpgrade;
	}
	
	public boolean supportsCastle() {
		return this.supportsCastle;
	}
}
